public class MarketUser {

    String card;
    String username;
    String telephone;
    int grade;
    int count = 0;
    String[][] user = new String[100][3];
    int[] userg = new int[100];

    public void name(String card, String username, String telephone, int grade) {
        for (int i = 0; i < count; i++) {
            if (user[i][0].equals(card)) {
                System.out.println("会员号重复");
                return;
            }
        }
        if (count < user.length) {
            user[count][0] = card;
            user[count][1] = username;
            user[count][2] = telephone;
            userg[count] = grade;
            count++;
            System.out.println("添加成功");
            return;
        }
        System.out.println("用户达到上限");
        return;
    }

    public void inc(String card, int num) {
        for (int i = 0; i < count; i++) {
            if (user[i][0].equals(card)) {
                userg[i] = userg[i] + num;
                return;
            }
        }
        System.out.println("帐号不存在");
    }

    public void message() {
        for (int i = 0; i < count; i++) {
            for (int j = 0; j < 3; j++) {
                System.out.print(user[i][j] + "   ");
            }
            System.out.println(userg[i]);
        }
    }

    public String duihuan(String card, int num) {
        for(int i=0;i<count;i++){
            if(user[i][0].equals(card)) {
                if(userg[i]<num)
                    return null;
                userg[i] = userg[i] - num;
                return "兑换成功";
            }
        }
        return null;
    }
}


